<!DOCTYPE html>
<html>
    <head>
        <title>DOM Range Example</title>
        <script type="text/javascript">
            function insertContent() {
                var p1 = document.getElementById("p1"),
                    helloNode = p1.firstChild.firstChild,
                    worldNode = p1.lastChild,
                    range = document.createRange(),
                    span = document.createElement("span");
                    
                span.style.color = "red";
                span.appendChild(document.createTextNode("Inserted text"));
                
                range.setStart(helloNode, 2);
                range.setEnd(worldNode, 3);
                range.insertNode(span);
                                
            }
        </script>
    </head>
    <body><p id="p1"><b>Hello</b> world!</p>
        <input type="button" value="Insert Content" onclick="insertContent()">     
        <p><strong>Note:</strong> This example uses DOM ranges and will only work in browsers that support DOM ranges. This example will fail in Internet Explorer &lt; 9.</p>
   
    </body>
</html>
